<input type="hidden" value="{$data.id}" id="id"/>
<div class="box box-warning">
    <div class="box-header with-border">
        <h3 class="box-title">
            <empty name="data.id">添加角色<else />修改角色信息</empty>
        </h3>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <form role="form">
            <!-- text input -->
            <div class="form-group">
                <label>角色名称</label>
                <empty name="data.name">
                    <input id="name" type="text" class="form-control" placeholder="">
                    <else />
                    <input id="name" type="text" value="{$data.name}" class="form-control" placeholder="">
                </empty>
            </div>
            <div class="form-group">
                <label>权限设置</label>
                <div>
                    <select id="menus" class="form-control select2 select2-hidden-accessible" style="width:100%;" tabindex="-1" aria-hidden="false" multiple="multiple">
                        <volist name="data.sysmenu" id="vo" key="sysmenu">
                            <option value="{$vo.id}"
                            <volist name="data.rolesysmenu" id="vo2" key="rolesysmenu">
                                <if condition="$vo2.menu_id eq $vo['id']">
                                     selected="selected"
                                </if>
                            </volist>
                            >{$vo.name}</option>
                        </volist>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <!-- /.box-body -->
    <div class="box-footer">
        <button id="save" type="button" class="btn btn-info" style="width:120px;">保存</button>
        <button id="cancel" type="button" class="btn btn-default pull-right" style="width:90px;">取消</button>
    </div>
    <div class="overlay hidden">
        <i class="fa fa-refresh fa-spin"></i>
    </div>
</div>
<script type="text/javascript">
//模块名称定义
var moduleName = 'role';

$(".select2").select2({
    minimumResultsForSearch: Infinity,
    language: "zh-CN"
});

//取消
$('#cancel').on('click', function() {
    window.location.href = '__ADMIN__#' + moduleName;
});

$('#save').on('click', function() {
    showLoad();
    $.ajax({
        type : "post",
        url : '__ADMIN__/' + moduleName + '/addoreditdata',
        dataType:"json",
        data: {
            id : $('#id').val()
            ,name : $('#name').val()
            ,menus : $('#menus').val()
            //多条件查询在此添加提交数据
        },
        success : function(msg) {
            //layer.msg(msg.msg);
            if (msg.code == 0)
                $.scojs_message(msg.msg, $.scojs_message.TYPE_OK);
            else
                $.scojs_message(msg.msg, $.scojs_message.TYPE_ERROR);
            hideLoad();
        }
    });
});

//读取菜单
/*$(function() {
    $.ajax({
        type : "post",
        url : '__ADMIN__/' + moduleName + '/getMenu',
        dataType:"json",
        success : function(data) {
            var datas = [];
            //<volist name="data.menus" id="ddd">{$ddd.role_id}:{$ddd.menu_id}<br/></volist>
            for (var i = 0; i < data.length; i++) {
                var o = new Object();
                o.id = data[i].id;
                o.text = data[i].name;
                datas.push(o);
            }
            $("#menus").select2({
                data:datas,
                minimumResultsForSearch: Infinity,
                language: "zh-CN"
            });
        }
    });
});*/
</script>